﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('Base_ElevatorInfo.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('Base_ElevatorInfo.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除
      </a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
      <a-button
        v-if="hasPerm('Base_ElevatorInfo.Approval')"
        type="primary"
        icon="highlight"
        @click="handleApproval(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >批量审核
      </a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <!--<a-select-option key="Code">自定义编码</a-select-option>-->
                <!--<a-select-option key="Remark">电梯备注</a-select-option>-->
                <!--<a-select-option key="CustomJsonCode">预留json字段</a-select-option>-->
                <!--<a-select-option key="Sort">序号</a-select-option>-->
                <a-select-option key="E_Type">电梯类型</a-select-option>
                <a-select-option key="E_Brand">电梯品牌</a-select-option>
                <a-select-option key="E_Series">电梯系列</a-select-option>
                <a-select-option key="E_RoomType">机房类型</a-select-option>
                <a-select-option key="E_CounterWeight">对重类型</a-select-option>
                <!-- <a-select-option key="E_SameCode">同款编号</a-select-option> -->
                <a-select-option key="E_LiftCarType">轿厢类型</a-select-option>
                <!-- <a-select-option key="E_ShaftRemark">井道备注</a-select-option> -->
                <!-- <a-select-option key="E_MRRemark">机房备注</a-select-option> -->
                <a-select-option key="E_OpenDoorMode">开门方式</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button
              type="primary"
              @click="
                () => {
                  this.pagination.current = 1
                  this.getDataList()
                }
              "
            >查询
            </a-button
            >
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
          <a-col :md="6" :sm="24" style="text-align: end; float: right">
            <a-button
              @click="
                () => {
                  this.visible = false
                }
              "
            >
              <a-icon type="download" />
              <a :href="$rootUrl + forTemplate">下载模板表</a>
            </a-button>
            <a-button style="margin-left: 15px" type="primary" icon="login" @click="ImportData()">导入数据</a-button>
            <!--<a-button style="margin-left: 10px" type="primary" icon="logout" @click="ExportData()">导出数据</a-button>-->
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :scroll="{y:530}"
      :columns="columns"
      :rowKey="(row) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="true"
      size="small"
    >
      <span slot="showStatus" slot-scope="text">
        <template>
          <a-tag v-if="text == '0'" color="red">未审批</a-tag>
          <a-tag v-else-if="text == '1'" color="green">已审批</a-tag>
        </template>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleDetail(record.Id)">详情</a>
          <a-divider v-if="hasPerm('Base_ElevatorInfo.Edit')" type="vertical" />
          <a v-if="hasPerm('Base_ElevatorInfo.Edit')" @click="handleEdit(record.Id)">编辑</a>
          <a-divider v-if="hasPerm('Base_ElevatorInfo.Edit') && hasPerm('Base_ElevatorInfo.Delete')" type="vertical" />
          <a v-if="hasPerm('Base_ElevatorInfo.Delete')" @click="handleDelete([record.Id])">删除</a>
          <a-divider
            v-if="hasPerm('Base_ElevatorInfo.Delete') && hasPerm('Base_ElevatorInfo.Approval')"
            type="vertical"
          />
          <a v-if="hasPerm('Base_ElevatorInfo.Approval')" @click="handleApproval([record.Id])">审核</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
    <detail-form ref="detailForm" :parentObj="this"></detail-form>
    <import-form
      ref="importForm"
      :parentObj="this"
      leading="/Base_BasicData/Base_ElevatorInfo/ImportData"
      @onchange="getDataList"
    ></import-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import DetailForm from './DetailForm'
import ImportForm from '@/components/FileOperations/ImportForm'

const columns = [
  // { title: '自定义编码', dataIndex: 'Code', width: '10%' },
  { title: '排序', dataIndex: 'Sort', align: 'center' },
  { title: '电梯品牌', dataIndex: 'E_Brand', align: 'center' },
  { title: '电梯系列', dataIndex: 'E_Series', align: 'center' },
  // { title: '机房类型', dataIndex: 'E_RoomType', align: 'center' },
  // { title: '对重类型', dataIndex: 'E_CounterWeight', align: 'center' },
  { title: '载重', dataIndex: 'E_Load', align: 'center' },
  { title: '梯速', dataIndex: 'E_Speed', align: 'center' },
  // { title: '轿厢类型', dataIndex: 'E_LiftCarType', align: 'center' },
  // { title: '载重人数', dataIndex: 'E_LoadNum', align: 'center' },
  // { title: '最大停站数', dataIndex: 'E_MaxStop', width: '6%' },
  // { title: '最大提升高度', dataIndex: 'E_MaxLiftHeight', width: '7%' },
  { title: '井道宽', dataIndex: 'E_ShaftWidth', align: 'center' },
  { title: '井道深', dataIndex: 'E_ShaftDepth', align: 'center' },
  // { title: '机房宽度', dataIndex: 'E_MRWidth' },
  // { title: '机房深度', dataIndex: 'E_MRDepth' },
  // { title: '机房净高', dataIndex: 'E_MRNetHeight', width: '10%' },
  // { title: '轿厢宽度', dataIndex: 'E_LiftCarWidth', width: '10%' },
  // { title: '轿厢深度', dataIndex: 'E_LiftCarDepth', width: '10%' },
  // { title: '轿厢净高', dataIndex: 'E_LiftCarNetHeight', width: '10%' },
  { title: '顶层高度', dataIndex: 'E_TopHeight', align: 'center' },
  { title: '底坑深度', dataIndex: 'E_BottomDepth', align: 'center' },
  // { title: '开门方式', dataIndex: 'E_OpenDoorMode', align: 'center' },
  // { title: '轿厢门宽度', dataIndex: 'E_LiftCarDoorW', width: '10%' },
  // { title: '轿厢门高度', dataIndex: 'E_LiftCarDoorH', width: '10%' },
  // { title: '结构门宽度', dataIndex: 'E_StructuralDoorW', width: '10%' },
  // { title: '结构门高度', dataIndex: 'E_StructuralDoorH', width: '10%' },
  // { title: '电梯备注', dataIndex: 'Remark', width: '10%' },
  {
    title: '批准状态',
    dataIndex: 'ApprovalStatus',
    width: '5%',
    key: 'showStatus',
    align: 'center',
    scopedSlots: { customRender: 'showStatus' }
  },
  { title: '操作', dataIndex: 'action', width: '13%', scopedSlots: { customRender: 'action' }, align: 'center' }
]

export default {
  components: {
    ImportForm,
    EditForm,
    DetailForm
  },
  mounted () {
    this.getDataList()
  },
  data () {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['10', '20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面啊可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'Sort', order: 'desc' },
      loading: false,
      columns,
      forTemplate: '/Base_BasicData/Base_ElevatorInfo/ExportTemplateToExcel',
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange (pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList () {
      this.selectedRowKeys = []
      this.loading = true
      this.$http
        .post('/Base_BasicData/Base_ElevatorInfo/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Sort',
          SortType: this.sorter.order || 'desc',
          Search: this.queryParam,
          ...this.filters
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected () {
      return this.selectedRowKeys.length > 0
    },
    handleAdd () {
      this.$refs.editForm.openDrawer(null, '新建电梯信息')
    },
    ImportData () {
      this.$refs.importForm.openForm('数据导入 -->>请上传要导入的Excel文件')
    },
    ExportData () {
      var thisObj = this
      thisObj.$message.info('导出功能暂未开通!')
    },
    handleDetail (id) {
      this.$refs.detailForm.openDrawer(id, '电梯详情信息')
    },
    handleEdit (id) {
      this.$refs.editForm.openDrawer(id, '编辑电梯信息')
    },
    handleDelete (ids) {
      var thisObj = this
      this.$confirm({
        title: '确认删除吗?',
        onOk () {
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_BasicData/Base_ElevatorInfo/DeleteData', ids).then((resJson) => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
        }
      })
    },
    handleApproval (ids) {
      var thisObj = this
      this.$confirm({
        title: '确认审核吗?',
        onOk () {
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_BasicData/Base_ElevatorInfo/ApprovalStatus', ids).then((resJson) => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
        }
      })
    }
  }
}
</script>
